<?php
/** 
 * Created by RisingSun. 
 * User: MarkSpace 
 * Date: 20210822
 * Time: 11:05 
 */
namespace app\middleware;

use  Mscore\Core\Lang;
use  app\admin\model\Login as LoginModel;
use  Mscore\Core\Route;

class AuthCheck 
{
    public function processs()
    {
        global $success; global $error; global $users; global $language;
        $language = isset($_COOKIE['language'])?$_COOKIE['language']:'default';
        Lang::init($GLOBALS['language']);
        $success=Lang::get('Success');
        $error=Lang::get('Error');
        $url = isset($_SERVER['REQUEST_URI'])?$_SERVER['REQUEST_URI']:'';
        $route = Route::router($url);
        $auth = config('auth');
        if(!in_array(strtolower($route['m']),$auth['appname']) && !in_array(strtolower($route['c']),$auth['controller']) && !in_array(strtolower($route['a']),$auth['action'])){
        	$users = (new LoginModel)->isAuth();
        	// user($users);
        	if(isset($users['code'])&&$users['code']==401){
            	header("Location:".config('server.login_url'));
            	exit;
        	}
        }
    }
}
